package com.whfc.ms.api.mach.service.impl;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.entity.dto.msg.AppWarnMsgRecDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.service.SysMachTypeService;
import com.whfc.mach.dto.AppMachDTO;
import com.whfc.mach.dto.warn.AppMachWarnCountDTO;
import com.whfc.mach.dto.warn.AppWarnDetailDTO;
import com.whfc.mach.dto.warn.AppWarnMachRecordDTO;
import com.whfc.mach.dto.warn.AppWarnRuleDTO;
import com.whfc.mach.enums.WorkState;
import com.whfc.mach.param.warn.*;
import com.whfc.mach.service.AppMachWarnService;
import com.whfc.ms.api.mach.service.MsMachWarnService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author sun_guodong
 * @description
 * @date 2020-11-19
 */
@Service
public class MsMachWarnServiceImpl implements MsMachWarnService {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @DubboReference(interfaceClass = AppMachWarnService.class, version = "1.0.0")
    private AppMachWarnService appMachWarnService;

    @DubboReference(interfaceClass = SysMachTypeService.class, version = "1.0.0")
    private SysMachTypeService sysMachTypeService;

    @Override
    public AppMachWarnCountDTO warnNumStatic(Integer deptId, Integer state, Date startTime, Date endTime) {
        return appMachWarnService.warnNumStatic(deptId, state, startTime, endTime);
    }

    @Override
    public PageData<AppWarnRuleDTO> ruleList(Integer pageNum, Integer pageSize, Integer ruleType, String keyword, Integer deptId, Integer enableFlag) {
        return appMachWarnService.ruleList(pageNum, pageSize, ruleType, keyword, deptId, enableFlag);
    }

    @Override
    public void ruleDel(Integer ruleId) {
        appMachWarnService.ruleDel(ruleId);
    }

    @Override
    public void enable(AppWarnEnableParam request) {
        appMachWarnService.enable(request);
    }

    @Override
    public void ruleAdd(AppWarnRuleAddParam request) {
        appMachWarnService.ruleAdd(request);
    }

    @Override
    public void ruleEdit(AppWarnRuleEditParam request) {
        appMachWarnService.ruleEdit(request);
    }

    @Override
    public ListData<AppMachDTO> objectList(Integer ruleId) {
        return appMachWarnService.objectList(ruleId);
    }

    @Override
    public void objectAdd(AppWarnMachAddParam request) {
        appMachWarnService.objectAdd(request);
    }

    @Override
    public ListData<AppMachDTO> getMachList(Integer ruleId) {
        return appMachWarnService.getMachList(ruleId);
    }

    @Override
    public void setTime(AppWarnSetTimeParam request) {
        appMachWarnService.setTime(request);
    }

    @Override
    public AppWarnMsgRecDTO userList(Integer ruleId) {
        return appMachWarnService.userList(ruleId);
    }

    @Override
    public void userAdd(AppWarnSetUserParam request) {
        appMachWarnService.userAdd(request);
    }

    @Override
    public PageData<AppWarnMachRecordDTO> recordList(Integer pageNum, Integer pageSize, Integer deptId, Integer state, Integer ruleType, Date startTime, Date endTime) {
        return appMachWarnService.recordList(pageNum, pageSize, deptId, state, ruleType, startTime, endTime);
    }

    @Override
    public void recordHandle(SysUser user, AppWarnHandleParam request) {
        request.setUserId(user.getId());
        request.setUserName(user.getNickname());
        request.setPhone(user.getPhone());
        appMachWarnService.recordHandle(request);
    }

    @Override
    public void batchHandle(AppWarnBatchHandleParam param) {
        appMachWarnService.batchHandle(param);
    }

    @Override
    public void del(AppWarnBatchDelParam param) {
        appMachWarnService.del(param);
    }

    @Override
    public AppWarnDetailDTO recordDetail(Integer id) {
        AppWarnDetailDTO data = appMachWarnService.recordDetail(id);
        // 图标
        String icon = sysMachTypeService.getIcon(data.getMachType(), WorkState.IDLE.getValue());
        data.setIcon(icon);
        data.setMachTypeIcon(icon);
        return data;
    }

}
